var img = document.querySelector('.eye');
var input = document.querySelector('.pw');
var inputUse = document.querySelector('.useName');
var cue = document.querySelector('.cue');
var flag = 0;

input.onfocus = function () {
    img.src = 'images/close.png';
    if (input.value === '请输入密码') {
        input.value = '';
        input.type = 'password';
        input.style.color = '#000';
    }
}
input.onblur = function () {
    if (input.value === '') {
        img.src = 'images/close.png';
        input.value = '请输入密码';
        input.type = 'text';
        input.style.color = '#ccc';
    }
}
img.onclick = function () {
    if (input.value === '请输入密码') {
        input.style.color = '#000';
    }
    if (flag == 0 && input.value !== '请输入密码') {
        flag = 1;
        this.src = 'images/open.png';
        input.type = 'text';
    } else if (flag = 1 && input.value !== '请输入密码') {
        flag = 0;
        this.src = 'images/close.png';
        input.type = 'password';
    }
}
inputUse.onfocus = function () {
    if (inputUse.value === 'email') {
        inputUse.value = '';
        inputUse.style.color = '#000';
    }
}
inputUse.onblur = function () {
    if (inputUse.value === '') {
        inputUse.value = 'email';
        inputUse.style.color = '#ccc';
    }
}
/*login = function () {
    var loginDate = $("#loginForm").serialize();
    //loginDateJson = JSON.stringify(loginDate);
    var loginDate = decodeURIComponent(loginDate, true);

    // let loginFormDate = {};
    // let dataArr = $("#loginForm ").serializeArray();
    // $.each(dataArr, function () {
    //     loginFormDate[this.name] = this.value;
    // });
    let loginDateJson = JSON.stringify(loginDate);
    $.post("http://39.105.140.250:8080/basic/user/login", { "username": "1234@1234", "password": "1234" }, function (data) {
        console.log(date);
    })
}*/

login = function () {
    $("#errorInfo").text();
    var loginDate = $("#loginForm").serialize();
    var loginDate = decodeURIComponent(loginDate, true);
    //let loginDateJson = JSON.stringify(loginDate);
    $.post("/user/login", loginDate, function (result) {
        if (result.code == 200){
            let loginUser = result.data;
            loginUser = JSON.stringify(loginUser)
            localStorage.setItem("username",loginUser)
            window.location.href = "/home/homeUser.html"
        }else {
            $("#errorInfo").text(result.msg);
        }
    })
    // $.ajax({
    //     url:"http://39.105.140.250:8080/basic/user/login",
    //     type:"post",
    //     data:{ "username": "1234@1234", "password": "1234" },
    //     contentType:"application/json",
    //     complete:function (data) {
    //         console.log(data)
    //     }
    // })
}

